package com.tssup.fesco.config;

import com.xxl.job.core.executor.XxlJobExecutor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class XxlJobConfig {

    @Value("${xxl.job.admin.addresses}")
    private String adminAddress;

    @Value("${xxl.job.executor.appname}")
    private String executorAppName;

    @Value("${xxl.job.executor.ip}")
    private String executorIp;

    @Value("${xxl.job.executor.port}")
    private Integer executorPort;

    @Value("${xxl.job.executor.logpath}")
    private String executorLogPath;

    @Bean
    public XxlJobExecutor getXxlJobExecutor() throws Exception {
        XxlJobExecutor xxlJobExecutor = new XxlJobExecutor();
        xxlJobExecutor.setIp(executorIp);
        xxlJobExecutor.setPort(executorPort);
        xxlJobExecutor.setAppName(executorAppName);
        xxlJobExecutor.setAdminAddresses(adminAddress);
        xxlJobExecutor.setLogPath(executorLogPath);
        xxlJobExecutor.start();
        return xxlJobExecutor;
    }
}